<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/global.js"></script>
	</head>

	<body>

		<div id="xiugaic" style="display: none">
			<form class="layui-form" onsubmit="return false" id="xiugaif" lay-filter="xiugaif">
				<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
				<div class="layui-form-item">
					<h2>程序自动分配开关</h2>
					<div class="layui-input-block">
						<input type='checkbox' id='weight' lay-filter='auto' lay-skin='switch' lay-text='待分配|已分配' />
					</div>
				</div>
				<!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
			</form>
		</div>
		<script type="text/javascript">
			layui.use(['form', 'table', 'layer'], function() {
				var form = layui.form;
				var table = layui.table;
				var layer = layui.layer;
				var $ = layui.$;


				//开关监听事件2
				form.on('switch(auto)', function(data) {
					var id = null;
					if(data.elem.checked) {
						id = 1;
						$("#weight").prop("checked", true);
					} else {
						id = 0;
					}

					$.post(globalData.server + 'user/weight?token=' + globalData.getToken(), {
						id: id
					}, function(res) {
						if(res.code == 0) {
							layer.msg(res.msg);
						}
					})
				})

				layer.open({
					type: 1,
					area: ['500px', '400px'],
					content: $("#xiugaic")
				})
			});
		</script>
	</body>

</html>